<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="../../WEB-INF/c.tld" prefix="c" %>
	
<div class="main">
	<div class="container">
	
		<c:if test="${error != null}">
			<div class="alert alert-error">
				<bean:message key="${error }" />
    		</div>
		</c:if>
		
		<html:form action="${action }" method="post" onsubmit="return validateCodePromoForm(this);" styleClass="form-horizontal">
			<fieldset>
				<legend><bean:message key="codepromo.Form" /></legend>
					<html:hidden property="idCode" value="${codePromo.idCode }" />
					<div class="control-group">
						<label class="control-label" for="store"><bean:message key="article.Enseigne" /></label>
						<div class="controls">
							<select name="store">
								<c:forEach items="${listEnseigne}" var="enseigne">
									<c:if test="${codePromo.enseigne.idEnseigne == enseigne.idEnseigne}">
										<option value="${enseigne.idEnseigne}" selected="selected" >${enseigne.libelle}</option>
									</c:if>
									<c:if test="${codePromo.enseigne.idEnseigne != enseigne.idEnseigne}">
										<option value="${enseigne.idEnseigne}" >${enseigne.libelle}</option>
									</c:if>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="identifiantCode"><bean:message key="codepromo.id" /></label>
						<div class="controls">
							<html:text property="identifiantCode" size="16" maxlength="16" value="${codePromo.identifiantCode }" />
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="dateDebut"><bean:message key="codepromo.dateDebut" /></label>
							<div class="controls">
							<html:text property="dateDebut" size="16" maxlength="16" value="${dateDebut }" />
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="dateFin"><bean:message key="codepromo.dateFin" /></label>
							<div class="controls">
							<html:text property="dateFin" size="16" maxlength="16" value="${dateFin }"/>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="typePromo"><bean:message key="codepromo.type" /></label>
						<div class="controls">
							
							<select name="typePromo" id="typePromo">
								<c:forEach items="${typePromo }" var="type">
									<c:if test="${type == codePromo.type }">
										<option value="${type}" selected="selected">${type }</option>
									</c:if>
									<c:if test="${type != codePromo.type }">
										<option value="${type}">${type }</option>
									</c:if>
								</c:forEach>
							</select>
						</div>
					</div>	
					<div class="control-group" id="pourcentage">
						<label class="control-label" for="pourcentage"><bean:message key="codepromo.pourcentage" /></label>
						<div class="controls">
							<select name="pourcentage">
								<c:forEach var="entry" begin="1" end="70">
									<c:if test="${entry == codePromo.pourcentage }">
	 									<option value="${entry}" selected="selected">${entry}%</option>
	 								</c:if>
	 								<c:if test="${entry != codePromo.pourcentage }">
	 									<option value="${entry}">${entry}%</option>
	 								</c:if>
								</c:forEach>
								
							</select>
						</div>
					</div>				
					<div class="control-group" id="refArticle">
							<label class="control-label" for="refArticle"><bean:message key="article.RefArticle" /></label>
							<div class="controls">
							<html:text property="refArticle" size="16" maxlength="16" value="${codePromo.article.idArticle }"/>
						</div>
					</div>
					<div class="form-actions">
						<button class="btn btn-primary" type="submit"><bean:message key="general.valider" /></button>
					</div>
			</fieldset>
			<html:javascript formName="CodePromoForm" />
		</html:form>
	</div>
</div>

<script type="text/javascript">
document.observe("dom:loaded", function() {
	bindTypepromo();
});
$('typePromo').observe('change',function(evt){
	bindTypepromo();
});

function bindTypepromo()
{
	var option = $('typePromo').getValue();
	$('refArticle').setStyle({
		  display: 'block'
		});
	$('pourcentage').setStyle({
		  display: 'block'
	});
	if((option == "REDCMD") || (option == "REDKDO"))
	{
			
		$('refArticle').setStyle({
			  display: 'none'
			});
	}
	if(option == "REDKDO")
	{
		$('pourcentage').setStyle({
			  display: 'none'
		});
	}
}
</script>


	